package cn.tansanqinger.service.account.impl;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.tansanqinger.dao.sql.user.UserMessageDispose;
import cn.tansanqinger.pojo.User;
import cn.tansanqinger.service.account.IUserService;
import cn.tansanqinger.util.DateUtil;
import cn.tansanqinger.util.PageData;

@Service
public class UserServiceImpl implements IUserService{
	
	@Autowired
	private UserMessageDispose uDispose;

	@Override
	public User selectIdOne(String id) {
		return uDispose.selectOneId(Integer.parseInt(id));
	}

	@Override
	public PageData delete(String id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public PageData modification(HttpServletRequest request) {
		PageData pd = new PageData(request);
		User user = (User) request.getSession().getAttribute("user");
		user.setSex(Integer.parseInt(pd.getString("sex")));
		user.setGrade(Integer.parseInt(pd.getString("grade")));
		user.setBrithday(pd.getString("brithday"));
		System.err.println(pd.getString("brithday"));
		System.err.println(DateUtil.yearsComparePrecise(pd.getString("brithday")));
		user.setAge(DateUtil.yearsComparePrecise(pd.getString("brithday")));
		user.setSchool(pd.getString("school"));
		user.setPersignature(pd.getString("perSignature"));
		pd = new PageData();
		if(uDispose.updateById(user)) {
			pd.put("age", user.getAge());
			pd.put("code", "0");
			pd.put("msg", "修改成功");
		} else {
			pd.put("code", "-1");
			pd.put("msg", "修改失败");
		}
		return pd;
	}

}
